package org.jmc.refmanager.domain.dao.jpa;

import java.util.List;

import org.jmc.refmanager.domain.dao.RoleDao;
import org.jmc.refmanager.domain.model.Role;
import org.jmc.refmanager.util.ListUtil;
import org.springframework.stereotype.Repository;

@Repository("roleDao")
public class RoleDaoImpl extends GenericDaoJpa<Role, Integer> implements RoleDao {

	public RoleDaoImpl() {
		super(Role.class);
	}

	@Override
	@SuppressWarnings("unchecked")
	public Role findByRoleName(String roleName) {
		List<Role> rolesFound = super.find(Role.FIND_BY_NAME, roleName);
		return ListUtil.getFirstEvenIfNull(rolesFound);
	}

	@Override
	@SuppressWarnings("unchecked")
	public List<Role> findAllBut(String exceptRoleName) {
		return super.findByNamedQuery(Role.FIND_ALL_BUT, exceptRoleName);
	}

}
